<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://struts.apache.org/tags-html-el" prefix="html-el" %>
<%@taglib uri="http://struts.apache.org/tags-bean-el" prefix="bean-el" %>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@taglib uri="http://struts.apache.org/tags-logic-el" prefix="logic-el" %>
<%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@taglib uri="/WEB-INF/tld/application.tld" prefix="app" %>

<html-el:form action="/contaReceber.do">
	<html-el:hidden property="method" styleId="method"/>
	<!-- TABLE CENTER -->
	<table style="width: 100%">
		<tr>
			<td align="center" valign="top">
				<!-- CONTENT -->			
				<div class="content">
					<table class="con">
						<tr>
							<td>
								<table class="breadory">
									<tr>
										<td>Contas a Receber</td>
									</tr>
								</table>
							
								<table style="width:750px;height:400px">
									<tr>
										<td valign="top">
											<table style="width: 100%" class="tbDadosConsulta">
												<tr>
													<th style="width:25px"></th>
													<th>Descrição</th>
													<th style="width:110px">Vencimento</th>
													<th style="width:110px">Tipo</th>
													<th style="width:90px">Valor</th>
												</tr>
												<tr>
													<td colspan="6" align="center" style="color:#FFF; background-color: #9D2E2C;font-size:14px"><b>Vencido</b></td>
												</tr>
												<logic-el:present name="vencido" scope="request">
													<logic-el:iterate id="bean" name="vencido" scope="request" indexId="i">
														<tr class="linha${i%2}">
															<td style="text-align: center">
																<input type="checkbox" name="contaReceber" value="${bean.codigo}" title="Conta a Receber"/>
															</td>
															<td style="text-align: left">${bean.descricao}</td>
															<td style="text-align: center">
																<bean:write name="bean" property="vencimento" format="dd/MM/yyyy"/>
															</td>
															<td style="text-align: center">${bean.ordemServicoEspecie.formaPagamento.descricao}</td>
															<td style="text-align: right">
																<bean:write name="bean" property="valorPagamento" format="###,##0.00" locale="defaultLocale"/>
															</td>
														</tr>
														<logic:equal name="bean" property="ordemServicoEspecie.formaPagamento.value" value="2">
															<tr>
																<td style="text-align: center; background-color: #FFF"></td>
																<td style="text-align: left;background-color: #E6E6E6" colspan="4">
																	${bean.ordemServicoEspecie.banco.numero} - ${bean.ordemServicoEspecie.banco.nome} - <b>Agência:</b> ${bean.ordemServicoEspecie.agencia} - <b>Conta:</b> ${bean.ordemServicoEspecie.conta} - <b>Cheque:</b> ${bean.ordemServicoEspecie.cheque}
																</td>
															</tr>
														</logic:equal>
													</logic-el:iterate>
													<tr>
														<td colspan="4" align="right"><b>Total:</b></td>
														<td align="right">
															<bean:write name="totalVencido" format="###,##0.00" locale="defaultLocale"/>
														</td>
													</tr>
												</logic-el:present>
												<logic-el:notPresent name="vencido" scope="request">
													<tr>
														<td colspan="5" align="left">
															Não há.
														</td>
													</tr>
												</logic-el:notPresent>
												<logic-el:present name="vencido" scope="request"> 
													<tr>
														<td class="buttons" align="right" valign="bottom" colspan="5">
															<a href="javascript:confirmarRecebimentoIniciar()" class="button">
																<span>Confirmar Recebimento</span>
															</a>
														</td>
													</tr>
												</logic-el:present>											
												<tr>
													<td style="height:10px"></td>
												</tr>
												<tr>
													<td colspan="6" align="center" style="color:#FFF; background-color: #88aaaa;font-size:14px"><b>Receber Hoje - ${dataAtual}</b></td>
												</tr>
													<logic-el:present name="vencer" scope="request">
														<logic-el:iterate id="bean" name="vencer" scope="request" indexId="i">
															<tr class="linha0">
																<td style="text-align: center">
																	<logic:equal name="bean" property="situacao.name" value="PENDENTE">
																		<input type="checkbox" name="contaReceber" value="${bean.codigo}" title="Conta a Receber"/>
																	</logic:equal>
																	<logic:equal name="bean" property="situacao.name" value="PENDENTE_ALUNO">
																		<img src="_images/attention.gif" border="0"/>
																	</logic:equal>
																	<logic:equal name="bean" property="situacao.name" value="PAGO">
																		<img src="_images/status-ok.png" border="0"/>
																	</logic:equal>
																</td>
																<td style="text-align: left">${bean.descricao}</td>
																<td style="text-align: center">
																	<bean:write name="bean" property="vencimento" format="dd/MM/yyyy"/>
																</td>
																<td style="text-align: center">${bean.ordemServicoEspecie.formaPagamento.descricao}</td>
																<td style="text-align: right">
																	<bean:write name="bean" property="valorPagamento" format="###,##0.00" locale="defaultLocale"/>
																</td>
															</tr>
															<logic:equal name="bean" property="ordemServicoEspecie.formaPagamento.value" value="2">
																<tr>
																	<td style="text-align: center; background-color: #FFF"></td>
																	<td style="text-align: left;background-color: #E6E6E6" colspan="4">
																		${bean.ordemServicoEspecie.banco.numero} - ${bean.ordemServicoEspecie.banco.nome} - <b>Agência:</b> ${bean.ordemServicoEspecie.agencia} - <b>Conta:</b> ${bean.ordemServicoEspecie.conta} - <b>Cheque:</b> ${bean.ordemServicoEspecie.cheque}
																	</td>
																</tr>
															</logic:equal>
														</logic-el:iterate>	
														<tr>
															<td colspan="4" align="right"><b>Total:</b></td>
															<td align="right">
																<bean:write name="totalVencer" format="###,##0.00" locale="defaultLocale"/>
															</td>
														</tr>
													</logic-el:present>
													<logic-el:notPresent name="vencer" scope="request">
														<tr>
															<td colspan="5" align="left">
																Não há.
															</td>
														</tr>
													</logic-el:notPresent>
													<logic-el:present name="vencer" scope="request"> 
														<tr>
															<td class="buttons" align="right" valign="bottom" colspan="5">
																<a href="javascript:confirmarRecebimentoIniciar()" class="button">
																	<span>Confirmar Recebimento</span>
																</a>
															</td>
														</tr>
													</logic-el:present>
													<tr>
														<td style="height:10px"></td>
													</tr>
													<tr>
														<td colspan="6" align="center" style="color:#FFF; background-color: #4A4747;font-size:14px"><b>Lançamentos Futuros</b></td>
													</tr>
													<logic-el:present name="futuro" scope="request">
														<logic-el:iterate id="bean" name="futuro" scope="request" indexId="i">
															<tr class="linha${i%2}">
																<td style="text-align: center">
																	
																</td>
																<td style="text-align: left">${bean.descricao}</td>
																<td style="text-align: center">
																	<bean:write name="bean" property="vencimento" format="dd/MM/yyyy"/>
																</td>
																<td style="text-align: center">${bean.ordemServicoEspecie.formaPagamento.descricao}</td>
																<td style="text-align: right">
																	<bean:write name="bean" property="valorPagamento" format="###,##0.00" locale="defaultLocale"/>
																</td>
															</tr>
														</logic-el:iterate>
														<tr>
															<td colspan="4" align="right"><b>Total:</b></td>
															<td align="right">
																<bean:write name="totalFuturo" format="###,##0.00" locale="defaultLocale"/>
															</td>
														</tr>
													</logic-el:present>
													<logic-el:notPresent name="futuro" scope="request">
														<tr>
															<td colspan="5" align="left">
																Não há.
															</td>
														</tr>
													</logic-el:notPresent>
											</table>
										</td>
									</tr>
								</table>							
							</td>
						</tr>						
					</table>	
				</div>	
			</td>
		</tr>
	</table>
</html-el:form>
<div id="dialogConfirmarRecebimento" data-dojo-type="dijit.Dialog" title="Confirmar Recebimento - Cheque">
	<table class="formulario">
		<tr>
			<td class="label">Direcionamento do Cheque:</td>
			<td class="inputField">
				<app:comboDirecionamentoCheque styleId="direcionamentoCheque" title="Direcionamento do Cheque" style="width:350px"/>
			</td>
		</tr>
		<tr>
			<td class="buttons" align="right" valign="bottom" colspan="2">	
				<a href="javascript:cancelarConfirmarRecebimento()" class="button">
					<span>Cancelar</span>
				</a>
				<a href="javascript:confirmarRecebimento()" class="button">
					<span>Confirmar</span>
				</a>
			</td>
		</tr>
	</table>
</div>

<script type="text/javascript">

	function confirmarRecebimentoIniciar() {
		if(!mandatoryRadio('contaReceber', 'Confirmar o Recebimento'))
			return;
		
		document.getElementById("direcionamentoCheque").value = "";
		dijit.byId("dialogConfirmarRecebimento").show();		
	}
	function cancelarConfirmarRecebimento() {
		document.getElementById("direcionamentoCheque").value = "";
		dijit.byId("dialogConfirmarRecebimento").hide();
	}
	function confirmarRecebimento() {
		
		if(!mandatoryField('direcionamentoCheque')) {
			return;
		}
		
		if(!confirm("Confirma o depósito/recebimento do(s) cheque(s) selecionado(s) ?"))
			return;
		
		require(["dojo/_base/lang", "dojo/_base/xhr"], function(lang, xhr) {
			xhr.get({
		        url: "contaReceber.do?method=confirmarRecebimento",
		        timeout: ${ajaxTimeoutVoid},
		        form: document.forms[0],
		        content: {
		        	direcionamentoCheque: document.getElementById("direcionamentoCheque").value
		        },
		        load: function(data, ioArgs) {
		        	alert("Recebimento efetuado com sucesso!");
					window.location = "contaReceber.do?method=iniciar";
		        },
				error: function(data, ioArgs) {
					showAlertMessage("Erro ao realizar está operação! Tente novamente!");
		        }
		    });
		});		
	}
</script>